﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DAL;
using BUS;

namespace Quanlysieuthi
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        Connect cn = new Connect();

        private void button1_Click(object sender, EventArgs e)
        {
            string user = txttendangnhap.Text.Trim();
            string pass = txtmatkhau.Text.Trim();
            _Login nv = new _Login();
            int flag = nv.Dangnhap(user, pass);

            string sqlkt = "select count(*) from Login where TenDangNhap=N'" + txttendangnhap.Text + "'and MatKhau=N'" + txtmatkhau.Text + "' ";
            int kq = int.Parse(cn.loadlable(sqlkt));
            if (kq == 1)
            {
                if (flag == 1)
                {
                    MainMenu fr = new MainMenu();
                    this.Hide();
                    fr.Show();
                }
                if (flag == 0)
                {
                    DSMatHang fr = new DSMatHang();
                    fr.Show();
                }

            }
            else
            {
                MessageBox.Show("Tên đăng nhập hoặc mật khẩu không đúng ! Xin vui lòng nhập lại !");
                txttendangnhap.Clear();
                txtmatkhau.Clear();
            } 
        }
    }
}
